package com.magoldeditor.model;

import java.awt.Graphics;
import java.util.HashMap;

import com.magoldeditor.at.MaEditorXMLException;
import com.magoldeditor.model.entity.Entity;

/**
 * 
 * @author Velconia
 * @version v.2.0
 * 
 */
public class MaEditorCamera extends Entity implements ICamera, ICameraData {
	
	/**
	 * minimum times can be enlarged
	 */
	private static final double MINIMUN_TIMES = 0.0d;
	
	/**
	 * camera data
	 */
	private int x;
	private int y;
	private int width;
	private int height;
	
	/**
	 * map data
	 */
	private IMapData mapData;
	
	/**
	 * still to be thinked
	 */
	public MaEditorCamera(int x, int y, int width, int height, String name, IMapData mapData) {
		super(x, y, width, height, name);
		
		this.mapData = mapData;
	}
	
	/**
	 * init by itself
	 */
	public MaEditorCamera(String name, IMapData mapData) {
		super(name);
		
		try {
			init(name);
		} catch (MaEditorXMLException e) {
			e.printStackTrace();
		}
		this.mapData = mapData;
	}
	
	private void init(String name) throws MaEditorXMLException {
		ModelContants contants = ModelContants.getNewInstance();
		contants.initConfig(this);
	}

	@Override
	public void paintMethod(Graphics g) {
		
	}
	
	@Override
	public boolean toUp() {
		if (y >= 0) {
			y--; return true;
		} else return false;
	}

	@Override
	public boolean toDown() {
		if (y <= mapData.getHeight() - height) {
			y++; return true;
		} else return false;
	}

	@Override
	public boolean toRight() {
		if (x <= mapData.getWidth() - width) {
			x++; return true;
		} else return false;
	}

	@Override
	public boolean toLeft() {
		if (x >= 0) {
			x--; return true;
		} else return false;
	}

	@Override
	public boolean enlarge(double times) {
		if (times > MINIMUN_TIMES) {
			int tempWidth = (int) (this.width * times);
			int tempHeight = (int) (this.height * times);
			
			if (tempWidth <= mapData.getWidth() && 
					tempHeight <= mapData.getHeight()) {
				this.width = tempWidth;
				this.height = tempHeight;
				return true;
			}
		}
		
		return false;
	}

	@Override
	public void setX(int x) {
		if (x >= 0) this.x = x;
	}

	@Override
	public int getX() {
		return this.x;
	}

	@Override
	public void setY(int y) {
		if (y >= 0) this.y = y;
	}

	@Override
	public int getY() {
		return this.y;
	}

	@Override
	public void setWidth(int width) {
		if (width >= 0) this.width = width;
	}

	@Override
	public int getWidth() {
		return this.width;
	}

	@Override
	public void setHeight(int height) {
		if (height >= 0) this.height = height;
	}

	@Override
	public int getHeight() {
		return this.height;
	}

	@Override
	public HashMap<String, String> getConstructor() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setConstructor(HashMap<String, String> map) {
		// TODO Auto-generated method stub
		
	}
}
